//
// Description: 854. Floyd求最短路
// Created by Loading on 2022/5/21.
//

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 210;
constexpr int INF = 0x3f3f3f3f;

int n;
// dist[i][j] 表示从 i 到 j 之间的最短路长度
int dist[N][N];

void floyd() {
    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main() {
    int m, k;
    cin >> n >> m >> k;
    // dist[i][i] 初始化为 0，dist[i][j] 初始化为极大值
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) {
                dist[i][j] = 0;
            } else {
                dist[i][j] = INF;
            }
        }
    }

    for (int i = 0; i < m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        // 重边取最短
        dist[x][y] = min(dist[x][y], z);
    }

    floyd();

    for (int i = 0; i < k; ++i) {
        int x, y;
        cin >> x >> y;
        if (dist[x][y] > INF / 2) {
            puts("impossible");
        } else {
            cout << dist[x][y] << endl;
        }
    }

    return 0;
}
